<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\tool\Result;
use think\facade\View;
use think\Response;
use think\response\Json;
use app\common\model\News as NewsModel;

class News extends Base
{

    public function index()
    {
        return View::fetch();
    }

    public function info()
    {
        $id = $this->request->param('id');
        $info = NewsModel::where('id', $id)->find();
        if ($info->status != 1 || $info->is_del) {
            return redirect('/');
        }
        $info->hits = $info->hits + 1;
        $info->save();
        View::assign('info', $info);
        return View::fetch();
    }

    public function getList(): Response
    {
        return Result::fastReturn(NewsModel::getPageList([], 'id,title,images,create_time', $this->getPage()));
    }

}

